package cn.com.homeyoda.aimate.aihealth.ui.my.family;

import android.graphics.Typeface;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.core.content.ContextCompat;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.wzq.mvvmsmart.utils.GlideLoadUtils;

import java.util.List;

import cn.com.homeyoda.aimate.aihealth.R;
import cn.com.homeyoda.aimate.aihealth.bean.FamilyMembersBean;
import cn.com.homeyoda.aimate.aihealth.utils.StringUtils;

public class MembersAdapter extends BaseQuickAdapter<FamilyMembersBean.DataBean.FamilyMembers, BaseViewHolder> {

    private int selectPos = 0;

    public MembersAdapter(int layoutResId, @Nullable List<FamilyMembersBean.DataBean.FamilyMembers> data) {
        super(layoutResId, data);
    }

    @Override
    public void onBindViewHolder(BaseViewHolder holder, int position) {
        FamilyMembersBean.DataBean.FamilyMembers item = getData().get(position);
        holder.setText(R.id.tv_name, StringUtils.removeAllBank(item.getName()));
        ImageView ivAvatar = holder.getView(R.id.iv_avatar);
        GlideLoadUtils.loadImg(ivAvatar, item.getAvatar(), R.mipmap.ic_member1);
        TextView tvName = holder.getView(R.id.tv_name);
        if (selectPos == position) {
            tvName.setTypeface(null, Typeface.BOLD);
            holder.setTextColor(R.id.tv_name, ContextCompat.getColor(mContext, R.color.white));
            holder.setBackgroundRes(R.id.cl_root, R.mipmap.bg_family_management_active);
        } else {
            tvName.setTypeface(null, Typeface.NORMAL);
            holder.setTextColor(R.id.tv_name, ContextCompat.getColor(mContext, R.color.black_80));
            holder.setBackgroundRes(R.id.cl_root, R.mipmap.bg_family_management_inactive);
        }
        ConstraintLayout clRoot = holder.getView(R.id.cl_root);
        ViewGroup.LayoutParams layoutParams = clRoot.getLayoutParams();
        layoutParams.height = selectPos == position ? 100 : 80;
        clRoot.setLayoutParams(layoutParams);
    }

    @Override
    protected void convert(@NonNull BaseViewHolder helper, FamilyMembersBean.DataBean.FamilyMembers item) {
    }

    public void setSelectPos(int selectPos) {
        this.selectPos = selectPos;
        notifyDataSetChanged();
    }

    public int getSelectPos() {
        return selectPos;
    }
}
